@@ -6,18 +6,23 @@ import android.bluetooth.BluetoothDevice; |
||
6 | 6 |
import android.content.Intent; |
7 | 7 |
import android.os.Bundle; |
8 | 8 |
import android.support.annotation.Nullable; |
9 |
+import android.text.TextUtils; |
|
9 | 10 |
import android.view.View; |
10 | 11 |
import android.widget.AdapterView; |
12 |
+import android.widget.ImageView; |
|
11 | 13 |
import android.widget.ListView; |
12 | 14 |
import android.widget.TextView; |
13 | 15 |
import android.widget.Toast; |
14 | 16 |
import android.widget.ToggleButton; |
15 | 17 |
|
18 |
+import com.android.common.utils.DeviceUtils; |
|
19 |
+ |
|
16 | 20 |
import java.util.ArrayList; |
17 | 21 |
import java.util.List; |
18 | 22 |
|
19 | 23 |
import ai.pai.lensman.R; |
20 | 24 |
import ai.pai.lensman.base.BaseActivity; |
25 |
+import ai.pai.lensman.qrcode.QRCreateUtils; |
|
21 | 26 |
import butterknife.BindView; |
22 | 27 |
import butterknife.ButterKnife; |
23 | 28 |
import butterknife.OnCheckedChanged; |
@@ -29,6 +34,7 @@ public class PrinterSettingActivity extends BaseActivity implements PrinterSetti |
||
29 | 34 |
@BindView(R.id.tv_printer_status) TextView printerStatusText; |
30 | 35 |
@BindView(R.id.tv_bluetooth_status) TextView bluetoothStatusText; |
31 | 36 |
@BindView(R.id.tb_bluetooth_switch) ToggleButton btSwitchToggle; |
37 |
+ @BindView(R.id.iv_qrcode) ImageView qrCodeImg; |
|
32 | 38 |
|
33 | 39 |
private BluetoothDeviceListAdapter deviceAdapter; |
34 | 40 |
private PrinterSettingContract.Presenter presenter; |
@@ -36,12 +42,29 @@ public class PrinterSettingActivity extends BaseActivity implements PrinterSetti |
||
36 | 42 |
public static final int REQUEST_ENABLE_BT = 2; |
37 | 43 |
public static final int REQUEST_CONNECT_DEVICE = 3; |
38 | 44 |
|
45 |
+ private String qrcode; |
|
39 | 46 |
@Override |
40 | 47 |
protected void onCreate(@Nullable Bundle savedInstanceState) { |
41 | 48 |
super.onCreate(savedInstanceState); |
42 | 49 |
setContentView(R.layout.activity_printer_setting); |
43 | 50 |
unbinder = ButterKnife.bind(this); |
44 | 51 |
|
52 |
+ qrcode = getIntent().getStringExtra("qrcode"); |
|
53 |
+ if(TextUtils.isEmpty(qrcode)){ |
|
54 |
+ finish(); |
|
55 |
+ return; |
|
56 |
+ } |
|
57 |
+ qrCodeImg.post(new Runnable() { |
|
58 |
+ @Override |
|
59 |
+ public void run() { |
|
60 |
+ try{ |
|
61 |
+ qrCodeImg.setImageBitmap(QRCreateUtils.Create2DCode(qrcode, DeviceUtils.dip2px(PrinterSettingActivity.this,240))); |
|
62 |
+ }catch (Exception e){ |
|
63 |
+ e.printStackTrace(); |
|
64 |
+ } |
|
65 |
+ } |
|
66 |
+ }); |
|
67 |
+ |
|
45 | 68 |
deviceAdapter = new BluetoothDeviceListAdapter(this); |
46 | 69 |
btDevicesList.setAdapter(deviceAdapter); |
47 | 70 |
btDevicesList.setOnItemClickListener(this); |
@@ -106,8 +129,8 @@ public class PrinterSettingActivity extends BaseActivity implements PrinterSetti |
||
106 | 129 |
} |
107 | 130 |
|
108 | 131 |
@OnClick(R.id.tv_print_test) |
109 |
- void testPrint(){ |
|
110 |
- presenter.printTestPage(); |
|
132 |
+ void printerQR(){ |
|
133 |
+ presenter.printQR(qrcode); |
|
111 | 134 |
} |
112 | 135 |
|
113 | 136 |
@OnClick(R.id.title_bar_back_layout) |
@@ -14,7 +14,7 @@ public class PrinterSettingContract { |
||
14 | 14 |
void start(); |
15 | 15 |
void stop(); |
16 | 16 |
void queryPrinterStatus(); |
17 |
- void printTestPage(); |
|
17 |
+ void printQR(String qrCodeStr); |
|
18 | 18 |
boolean queryBluetoothStatus(); |
19 | 19 |
List<BluetoothDevice> queryPairedDevices(); |
20 | 20 |
void discoverNewDevices(); |
@@ -10,18 +10,26 @@ import android.content.IntentFilter; |
||
10 | 10 |
import android.content.ServiceConnection; |
11 | 11 |
import android.os.IBinder; |
12 | 12 |
import android.os.RemoteException; |
13 |
+import android.text.TextUtils; |
|
14 |
+import android.util.Base64; |
|
13 | 15 |
import android.util.Log; |
14 | 16 |
|
15 | 17 |
import com.android.common.utils.LogHelper; |
16 | 18 |
import com.gprinter.aidl.GpService; |
19 |
+import com.gprinter.command.EscCommand; |
|
17 | 20 |
import com.gprinter.command.GpCom; |
18 | 21 |
import com.gprinter.io.GpDevice; |
19 | 22 |
import com.gprinter.io.PortParameters; |
20 | 23 |
import com.gprinter.service.GpPrintService; |
21 | 24 |
|
25 |
+import org.apache.commons.lang.ArrayUtils; |
|
26 |
+ |
|
27 |
+import java.text.SimpleDateFormat; |
|
22 | 28 |
import java.util.ArrayList; |
29 |
+import java.util.Date; |
|
23 | 30 |
import java.util.List; |
24 | 31 |
import java.util.Set; |
32 |
+import java.util.Vector; |
|
25 | 33 |
|
26 | 34 |
import ai.pai.lensman.App; |
27 | 35 |
import ai.pai.lensman.R; |
@@ -117,17 +125,52 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter |
||
117 | 125 |
} |
118 | 126 |
} |
119 | 127 |
|
128 |
+ |
|
120 | 129 |
@Override |
121 |
- public void printTestPage() { |
|
130 |
+ public void printQR(String qrCodeStr) { |
|
131 |
+ if(TextUtils.isEmpty(Preferences.getInstance().getPrinterMac())){ |
|
132 |
+ view.showToast(App.getAppContext().getString(R.string.not_set_printer_yet)); |
|
133 |
+ return; |
|
134 |
+ } |
|
135 |
+ EscCommand esc = new EscCommand(); |
|
136 |
+ esc.addPrintAndFeedLines((byte) 3); |
|
137 |
+ esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER);//设置打印居中 |
|
138 |
+ esc.addSelectPrintModes(EscCommand.FONT.FONTA, EscCommand.ENABLE.OFF, EscCommand.ENABLE.ON, EscCommand.ENABLE.ON, EscCommand.ENABLE.OFF);//设置为倍高倍宽 |
|
139 |
+ esc.addText("拍爱\n"); // 打印文字 |
|
140 |
+ esc.addPrintAndLineFeed(); |
|
141 |
+ |
|
142 |
+ /*打印文字*/ |
|
143 |
+ esc.addSelectPrintModes(EscCommand.FONT.FONTA, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF);//取消倍高倍宽 |
|
144 |
+ esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT);//设置打印左对齐 |
|
145 |
+ esc.addText("欢迎使用拍爱!\n"); // 打印文字 |
|
146 |
+ |
|
147 |
+ /*QRCode命令打印 |
|
148 |
+ 此命令只在支持QRCode命令打印的机型才能使用。 |
|
149 |
+ 在不支持二维码指令打印的机型上,则需要发送二维条码图片 |
|
150 |
+ */ |
|
151 |
+ esc.addSelectErrorCorrectionLevelForQRCode((byte) 0x31); //设置纠错等级 |
|
152 |
+ esc.addSelectSizeOfModuleForQRCode((byte)10);//设置qrcode模块大小 |
|
153 |
+ esc.addStoreQRCodeData(qrCodeStr);//设置qrcode内容 |
|
154 |
+ esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER);//设置打印中心对齐 |
|
155 |
+ esc.addPrintQRCode();//打印QRCode |
|
156 |
+ esc.addPrintAndFeedLines((byte) 3); |
|
157 |
+ esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT);//设置打印左对齐 |
|
158 |
+ esc.addText("拍摄日期 "+new SimpleDateFormat("yyyy/MM/dd HH:mm").format(new Date())); |
|
159 |
+ esc.addPrintAndFeedLines((byte) 3); |
|
160 |
+ |
|
161 |
+ Vector<Byte> datas = esc.getCommand(); //发送数据 |
|
162 |
+ Byte[] Bytes = datas.toArray(new Byte[datas.size()]); |
|
163 |
+ byte[] bytes = ArrayUtils.toPrimitive(Bytes); |
|
164 |
+ String str = Base64.encodeToString(bytes, Base64.DEFAULT); |
|
165 |
+ int rel; |
|
122 | 166 |
try { |
123 |
- int rel = mGpService.printeTestPage(0); // |
|
124 |
- Log.i("ServiceConnection", "rel " + rel); |
|
167 |
+ rel = mGpService.sendEscCommand(0, str); |
|
125 | 168 |
GpCom.ERROR_CODE r = GpCom.ERROR_CODE.values()[rel]; |
126 | 169 |
if (r != GpCom.ERROR_CODE.SUCCESS) { |
127 | 170 |
view.showToast( GpCom.getErrorText(r)); |
128 | 171 |
} |
129 |
- } catch (Exception e1) { |
|
130 |
- e1.printStackTrace(); |
|
172 |
+ } catch (Exception e) { |
|
173 |
+ view.showToast(App.getAppContext().getString(R.string.go_check_printer)); |
|
131 | 174 |
} |
132 | 175 |
} |
133 | 176 |
|
@@ -17,6 +17,7 @@ import ai.pai.lensman.bean.PhotoBean; |
||
17 | 17 |
import ai.pai.lensman.bean.SessionBean; |
18 | 18 |
import ai.pai.lensman.printer.PrinterSettingActivity; |
19 | 19 |
import ai.pai.lensman.qrcode.QRCaptureActivity; |
20 |
+import ai.pai.lensman.utils.UrlContainer; |
|
20 | 21 |
import butterknife.BindView; |
21 | 22 |
import butterknife.ButterKnife; |
22 | 23 |
import butterknife.OnClick; |
@@ -94,7 +95,10 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie |
||
94 | 95 |
|
95 | 96 |
@OnClick(R.id.iv_qrcode) |
96 | 97 |
void showQRCodeForSession(){ |
97 |
- new SessionQRPopup(this, sessionBean.sessionId,this).showPopupWindow(); |
|
98 |
+// new SessionQRPopup(this, sessionBean.sessionId,this).showPopupWindow(); |
|
99 |
+ Intent intent = new Intent(this,PrinterSettingActivity.class); |
|
100 |
+ intent.putExtra("qrcode", UrlContainer.HOST_URL+sessionBean.sessionId); |
|
101 |
+ startActivity(intent); |
|
98 | 102 |
} |
99 | 103 |
|
100 | 104 |
@OnClick(R.id.title_bar_back_layout) |
@@ -143,7 +147,9 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie |
||
143 | 147 |
@Override |
144 | 148 |
public void onClick(View view) { |
145 | 149 |
if(view.getId()==R.id.btn_print_qr){ |
146 |
- presenter.printQR(); |
|
150 |
+ Intent intent = new Intent(this,PrinterSettingActivity.class); |
|
151 |
+ intent.putExtra("qrcode",sessionBean.sessionId); |
|
152 |
+ startActivity(intent); |
|
147 | 153 |
}else if(view.getId()==R.id.tv_printer_set){ |
148 | 154 |
startActivity(new Intent(this, PrinterSettingActivity.class)); |
149 | 155 |
} |
@@ -18,6 +18,5 @@ public class SessionContract { |
||
18 | 18 |
|
19 | 19 |
interface Presenter extends BasePresenter{ |
20 | 20 |
void swipeToDeletePhoto(int index); |
21 |
- void printQR(); |
|
22 | 21 |
} |
23 | 22 |
} |
@@ -1,34 +1,13 @@ |
||
1 | 1 |
package ai.pai.lensman.session; |
2 | 2 |
|
3 |
-import android.content.ComponentName; |
|
4 |
-import android.content.Context; |
|
5 | 3 |
import android.content.Intent; |
6 |
-import android.content.ServiceConnection; |
|
7 |
-import android.os.IBinder; |
|
8 |
-import android.text.TextUtils; |
|
9 |
-import android.util.Base64; |
|
10 |
-import android.util.Log; |
|
11 |
- |
|
12 |
-import com.android.common.utils.LogHelper; |
|
13 |
-import com.gprinter.aidl.GpService; |
|
14 |
-import com.gprinter.command.EscCommand; |
|
15 |
-import com.gprinter.command.GpCom; |
|
16 |
-import com.gprinter.io.PortParameters; |
|
17 |
-import com.gprinter.service.GpPrintService; |
|
18 |
- |
|
19 |
-import org.apache.commons.lang.ArrayUtils; |
|
20 |
- |
|
21 |
-import java.text.SimpleDateFormat; |
|
4 |
+ |
|
22 | 5 |
import java.util.ArrayList; |
23 |
-import java.util.Date; |
|
24 |
-import java.util.Vector; |
|
25 | 6 |
|
26 | 7 |
import ai.pai.lensman.App; |
27 |
-import ai.pai.lensman.R; |
|
28 | 8 |
import ai.pai.lensman.bean.PhotoBean; |
29 | 9 |
import ai.pai.lensman.bean.SessionBean; |
30 | 10 |
import ai.pai.lensman.db.DBService; |
31 |
-import ai.pai.lensman.db.Preferences; |
|
32 | 11 |
import ai.pai.lensman.service.UploadService; |
33 | 12 |
|
34 | 13 |
|
@@ -40,9 +19,6 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter |
||
40 | 19 |
private SessionBean sessionBean; |
41 | 20 |
private boolean isWorking; |
42 | 21 |
|
43 |
- private GpService mGpService = null; |
|
44 |
- private PrinterServiceConnection conn = null; |
|
45 |
- private int mPrinterId = 0; |
|
46 | 22 |
|
47 | 23 |
|
48 | 24 |
public SessionPresenter(SessionBean sessionBean, SessionContract.View view) { |
@@ -63,16 +39,12 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter |
||
63 | 39 |
} |
64 | 40 |
} |
65 | 41 |
interactor.startSession(); |
66 |
- startAndBindPrintService(); |
|
67 | 42 |
} |
68 | 43 |
|
69 | 44 |
@Override |
70 | 45 |
public void stop() { |
71 | 46 |
interactor.endSession(); |
72 | 47 |
isWorking = false; |
73 |
- if (conn != null) { |
|
74 |
- App.getAppContext().unbindService(conn); |
|
75 |
- } |
|
76 | 48 |
} |
77 | 49 |
|
78 | 50 |
@Override |
@@ -111,102 +83,4 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter |
||
111 | 83 |
interactor.deletePhoto(photoBean); |
112 | 84 |
} |
113 | 85 |
|
114 |
- @Override |
|
115 |
- public void printQR() { |
|
116 |
- if(TextUtils.isEmpty(Preferences.getInstance().getPrinterMac())){ |
|
117 |
- sessionView.showToast(App.getAppContext().getString(R.string.not_set_printer_yet)); |
|
118 |
- return; |
|
119 |
- } |
|
120 |
- checkPrinter(); |
|
121 |
- EscCommand esc = new EscCommand(); |
|
122 |
- esc.addPrintAndFeedLines((byte) 3); |
|
123 |
- esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER);//设置打印居中 |
|
124 |
- esc.addSelectPrintModes(EscCommand.FONT.FONTA, EscCommand.ENABLE.OFF, EscCommand.ENABLE.ON, EscCommand.ENABLE.ON, EscCommand.ENABLE.OFF);//设置为倍高倍宽 |
|
125 |
- esc.addText("拍爱\n"); // 打印文字 |
|
126 |
- esc.addPrintAndLineFeed(); |
|
127 |
- |
|
128 |
- /*打印文字*/ |
|
129 |
- esc.addSelectPrintModes(EscCommand.FONT.FONTA, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF);//取消倍高倍宽 |
|
130 |
- esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT);//设置打印左对齐 |
|
131 |
- esc.addText("欢迎使用拍爱!\n"); // 打印文字 |
|
132 |
- |
|
133 |
- /*QRCode命令打印 |
|
134 |
- 此命令只在支持QRCode命令打印的机型才能使用。 |
|
135 |
- 在不支持二维码指令打印的机型上,则需要发送二维条码图片 |
|
136 |
- */ |
|
137 |
- esc.addText("Print QRCode\n"); // 打印文字 |
|
138 |
- esc.addPrintAndFeedLines((byte) 3); |
|
139 |
- esc.addSelectErrorCorrectionLevelForQRCode((byte) 0x31); //设置纠错等级 |
|
140 |
- esc.addSelectSizeOfModuleForQRCode((byte)10);//设置qrcode模块大小 |
|
141 |
- esc.addStoreQRCodeData(sessionBean.sessionId);//设置qrcode内容 |
|
142 |
- esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER);//设置打印中心对齐 |
|
143 |
- esc.addPrintQRCode();//打印QRCode |
|
144 |
- esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT);//设置打印左对齐 |
|
145 |
- esc.addText("拍摄日期 "+new SimpleDateFormat("yy/MM/dd HH:mm").format(new Date())); |
|
146 |
- esc.addPrintAndFeedLines((byte) 3); |
|
147 |
- |
|
148 |
- Vector<Byte> datas = esc.getCommand(); //发送数据 |
|
149 |
- Byte[] Bytes = datas.toArray(new Byte[datas.size()]); |
|
150 |
- byte[] bytes = ArrayUtils.toPrimitive(Bytes); |
|
151 |
- String str = Base64.encodeToString(bytes, Base64.DEFAULT); |
|
152 |
- int rel; |
|
153 |
- try { |
|
154 |
- rel = mGpService.sendEscCommand(mPrinterId, str); |
|
155 |
- GpCom.ERROR_CODE r = GpCom.ERROR_CODE.values()[rel]; |
|
156 |
- if (r != GpCom.ERROR_CODE.SUCCESS) { |
|
157 |
- sessionView.showToast( GpCom.getErrorText(r)); |
|
158 |
- } |
|
159 |
- } catch (Exception e) { |
|
160 |
- sessionView.showToast(App.getAppContext().getString(R.string.go_check_printer)); |
|
161 |
- } |
|
162 |
- } |
|
163 |
- |
|
164 |
- private void checkPrinter(){ |
|
165 |
- sessionView.showToast(App.getAppContext().getString(R.string.connecting)); |
|
166 |
- try{ |
|
167 |
- int status = mGpService.queryPrinterStatus(0, 10000); |
|
168 |
- if (status != GpCom.STATE_NO_ERR) { |
|
169 |
- connectPrinter(); |
|
170 |
- } |
|
171 |
- }catch (Exception e){ |
|
172 |
- sessionView.showToast(App.getAppContext().getString(R.string.go_check_printer)); |
|
173 |
- return; |
|
174 |
- } |
|
175 |
- printQR(); |
|
176 |
- } |
|
177 |
- |
|
178 |
- public void connectPrinter() { |
|
179 |
- if(mGpService==null){ |
|
180 |
- sessionView.showToast(App.getAppContext().getString(R.string.printer_service_boot_fail)); |
|
181 |
- return; |
|
182 |
- } |
|
183 |
- try { |
|
184 |
- int code = mGpService.openPort(0, PortParameters.BLUETOOTH, Preferences.getInstance().getPrinterMac(), 0); |
|
185 |
- LogHelper.d("czy111","open port return code ="+code); |
|
186 |
- } catch (Exception e) { |
|
187 |
- sessionView.showToast(App.getAppContext().getString(R.string.printer_port_open_fail)); |
|
188 |
- } |
|
189 |
- |
|
190 |
- } |
|
191 |
- |
|
192 |
- private void startAndBindPrintService() { |
|
193 |
- Intent intent = new Intent(App.getAppContext(), GpPrintService.class); |
|
194 |
- App.getAppContext().startService(intent); |
|
195 |
- conn = new PrinterServiceConnection(); |
|
196 |
- App.getAppContext().bindService(intent, conn, Context.BIND_AUTO_CREATE); |
|
197 |
- } |
|
198 |
- |
|
199 |
- class PrinterServiceConnection implements ServiceConnection { |
|
200 |
- @Override |
|
201 |
- public void onServiceDisconnected(ComponentName name) { |
|
202 |
- Log.i("ServiceConnection", "onServiceDisconnected() called"); |
|
203 |
- mGpService = null; |
|
204 |
- } |
|
205 |
- |
|
206 |
- @Override |
|
207 |
- public void onServiceConnected(ComponentName name, IBinder service) { |
|
208 |
- mGpService = GpService.Stub.asInterface(service); |
|
209 |
- } |
|
210 |
- } |
|
211 |
- |
|
212 | 86 |
} |
@@ -65,6 +65,13 @@ |
||
65 | 65 |
android:layout_below="@id/title_bar_with_back_btn" |
66 | 66 |
android:orientation="vertical"> |
67 | 67 |
|
68 |
+ <ImageView |
|
69 |
+ android:id="@+id/iv_qrcode" |
|
70 |
+ android:layout_width="240dp" |
|
71 |
+ android:layout_height="240dp" |
|
72 |
+ android:layout_gravity="center_horizontal" |
|
73 |
+ android:layout_margin="8dp"/> |
|
74 |
+ |
|
68 | 75 |
<LinearLayout |
69 | 76 |
android:layout_width="match_parent" |
70 | 77 |
android:layout_height="38dp" |
@@ -111,7 +118,7 @@ |
||
111 | 118 |
android:id="@+id/tv_print_test" |
112 | 119 |
android:layout_width="wrap_content" |
113 | 120 |
android:layout_height="wrap_content" |
114 |
- android:text="@string/print_test" |
|
121 |
+ android:text="@string/print_qr" |
|
115 | 122 |
android:textColor="@color/dark_grey" |
116 | 123 |
android:textSize="16sp" /> |
117 | 124 |
</LinearLayout> |